﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for CompaignClass
/// </summary>
public class CompaignClass:BaseClass
{
    public static int AddCompaign(Compains comp)
    {
        string query = String.Format("insert into COMPAIGN values('{0}','{1}','{2}','{3}','{4}','{5}')"
            , comp.Code, comp.StartDate, comp.EndDate, comp.Type, comp.Center, comp.Place);
        return RunDML(query);
    }
    public static int UpdateCompaign(Compains comp)
    {
        string query = String.Format("update COMPAIGN set CODE='{0}' ,BEGIN_date='{1}',END_date='{2}',TYPE='{3}',CENTER='{4}',PLACE='{5}' where CODE='{0}'"
            , comp.Code, comp.StartDate, comp.EndDate, comp.Type, comp.Center, comp.Place);
        return RunDML(query);
    }

    public static int DeleteCompaign(string Id)
    {
        string query = String.Format("delete from COMPAIGN where CODE={0}", Id);
        return RunDML(query);
    }
    public static DataTable SearchCompaign(string Field, string value)
    {
        string query = String.Format("select * from COMPAIGN where {0} like '%{1}%'", Field, value);
        return RunSelect(query);
    }

    public static int AddComp_Emp(string CompCode,string[] EmpID)
    {
        for (int x = 0; x < EmpID.Length; x++)
        {
            string query = String.Format("insert into COMP_EMP values('{0}','{1}')", CompCode, EmpID[x]);
            int y = RunDML(query);
            if (y == 0)
            {
                return 0;
            }
        }
        return 1;
    }
}